package com.zyh.resp;
import com.zyh.type.CodeStatusEnum;
import lombok.Data;

@Data
public class Result<T> {
    private boolean success;
    private int code;
    private String message;
    private T data;

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.success = true;
        result.code = CodeStatusEnum.SUCCESS.getCode();
        result.message = CodeStatusEnum.SUCCESS.getMessage();
        result.data = data;
        return result;
    }

    public static <T> Result<T> success() {
        return success(null);
    }

    public static <T> Result<T> fail(CodeStatusEnum code) {
        Result<T> result = new Result<>();
        result.success = false;
        result.code = code.getCode();
        result.message = code.getMessage();
        return result;
    }
}
